import java.util.Arrays;
import java.util.Scanner;

public class demo01 {
    //扫地机器人
    public static int n;
    public static int k;
    public static int[] arr;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        k = sc.nextInt();
        arr = new int[k];
        for (int i = 0; i < k; i++) {
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        int left = 0;
        int right = n;
        while (left < right) {
            int mid = (left + right) / 2;
            if (check(mid)) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        System.out.println((left-1) * 2);
    }

    public static boolean check(int mid) {
        int pos = 0;
        for (int i = 0; i < k; i++) {
            if (arr[i] - pos <= mid) {
                pos = Math.min(arr[i], pos + 1) + mid - 1;
            }
            if (pos >= n) {
                return true;
            }
        }
        return false;
    }
}
